import { IsOptional, IsNumber, Min, Max, IsArray } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';

export class CreateShortsFavoriteDto {
  @ApiProperty({ description: '短剧ID', example: 1 })
  @IsNumber()
  shortsId: number;
}

export class BatchDeleteFavoritesDto {
  @ApiProperty({
    description: '要删除的短剧ID数组',
    example: [1, 2, 3],
    type: [Number],
  })
  @IsArray()
  @IsNumber({}, { each: true })
  shortsIds: number[];
}

export class BatchDeleteFavoritesResponseDto {
  @ApiProperty({ description: '删除成功的数量' })
  deletedCount: number;

  @ApiProperty({ description: '删除失败的短剧ID列表' })
  failedShortsIds: number[];

  @ApiProperty({ description: '操作消息' })
  message: string;
}

export class ShortsFavoritesQueryDto {
  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsOptional()
  @Transform(({ value }) => parseInt(value))
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页大小', example: 20, required: false })
  @IsOptional()
  @Transform(({ value }) => parseInt(value))
  @IsNumber()
  @Min(1)
  @Max(100)
  pageSize?: number = 20;
}

export class ShortsFavoriteResponseDto {
  @ApiProperty({ description: '操作类型', enum: ['favorited', 'unfavorited'] })
  action: string;

  @ApiProperty({ description: '收藏ID', required: false })
  id?: number;

  @ApiProperty({ description: '用户ID', required: false })
  userId?: number;

  @ApiProperty({ description: '短剧ID', required: false })
  shortsId?: number;

  @ApiProperty({ description: '创建时间', required: false })
  createdAt?: string;

  @ApiProperty({ description: '是否已收藏' })
  isFavorited: boolean;

  @ApiProperty({ description: '操作消息', required: false })
  message?: string;
}

export class ShortsFavoriteInfoDto {
  @ApiProperty({ description: '收藏ID' })
  id: number;

  @ApiProperty({ description: '短剧ID' })
  shortsId: number;

  @ApiProperty({ description: '短剧标题' })
  title: string;

  @ApiProperty({ description: '封面图片URL' })
  coverUrl: string;

  @ApiProperty({ description: '短剧简介', required: false })
  summary?: string;

  @ApiProperty({ description: '导演姓名' })
  instructor: string;

  @ApiProperty({ description: '观看次数' })
  viewCount: number;

  @ApiProperty({ description: '点赞数量' })
  likeCount: number;

  @ApiProperty({ description: '收藏数量' })
  favoriteCount: number;

  @ApiProperty({ description: '是否置顶' })
  isTop: boolean;

  @ApiProperty({ description: '是否免费' })
  isFree: boolean;

  @ApiProperty({ description: '短剧状态' })
  status: string;

  @ApiProperty({ description: '分类信息' })
  category: {
    id: number;
    name: string;
  };

  @ApiProperty({ description: '方向信息' })
  direction: {
    id: number;
    name: string;
  };

  @ApiProperty({ description: '收藏时间' })
  createdAt: string;
}

export class ShortsFavoritesListResponseDto {
  @ApiProperty({ description: '收藏列表' })
  list: ShortsFavoriteInfoDto[];

  @ApiProperty({ description: '分页信息' })
  pagination: {
    page: number;
    pageSize: number;
    total: number;
    totalPages: number;
  };
}

// 用于Swagger文档的完整API响应类型
export class ApiShortsFavoriteResponseDto {
  @ApiProperty({ description: '响应状态码', example: 200 })
  code: number;

  @ApiProperty({ description: '响应消息', example: 'success' })
  message: string;

  @ApiProperty({ description: '响应数据' })
  data: ShortsFavoriteResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

export class ApiShortsFavoritesListResponseDto {
  @ApiProperty({ description: '响应状态码', example: 200 })
  code: number;

  @ApiProperty({ description: '响应消息', example: 'success' })
  message: string;

  @ApiProperty({ description: '响应数据' })
  data: ShortsFavoritesListResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

export class ApiBatchDeleteFavoritesResponseDto {
  @ApiProperty({ description: '响应状态码', example: 200 })
  code: number;

  @ApiProperty({ description: '响应消息', example: 'success' })
  message: string;

  @ApiProperty({ description: '响应数据' })
  data: BatchDeleteFavoritesResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}
